<?

class Configurazioni 
{
	var $id_negozio;
	var $db;
	var $params;
	
	function Configurazioni($id_negozio, &$db)
	{
		$this->id_negozio = $id_negozio;
		$this->db = &$db;
		if(!is_array($_SESSION[configurazione]))$this->buildSession();
		else $this->params = $_SESSION[configurazione];
		
	}
	
	function buildSession()
	{
		if($this->id_negozio)
		{
			
			$_SESSION[configurazione] = null;	
			$query = "SELECT * FROM moka_ecommerce.configurazioni WHERE id_negozio=\"$this->id_negozio\" ";	
			$result = $this->db->query($query);
			if(!$result)exit("Mancano configurazioni.");
			$rw = mysql_fetch_assoc($result);
			$_SESSION[configurazione] = $rw;
			$this->params = $rw;
			
			$query = "SELECT * FROM  moka_ecomm_$this->id_negozio.dati ";	
			$result = $this->db->query($query);
			if(!$result)exit("Mancano dati negozio.");
			while($rw = mysql_fetch_assoc($result))
				$_SESSION[configurazione][$rw[nome]] = $rw[valore];
				$this->params[$rw[nome]] = $rw[valore];

			
		}
		
	}
	
	function get_param($nome)
	{
		return $this->params[$nome];
	}
	
	function SaveGen()
	{
		if($this->id_negozio)
		{
			$query = "REPLACE INTO moka_ecommerce.configurazioni 
						SET id_negozio=\"$this->id_negozio\", 
						nome=\"$_REQUEST[nome]\",
						img_L_width=\"$_REQUEST[img_L_width]\",
						img_L_height=\"$_REQUEST[img_L_height]\",
						crop_L=\"".(0+$_REQUEST[crop_L])."\",
						img_M_width=\"$_REQUEST[img_M_width]\",
						img_M_height=\"$_REQUEST[img_M_height]\",
						crop_M=\"".(0+$_REQUEST[crop_M])."\",
						img_S_width=\"$_REQUEST[img_S_width]\",
						img_S_height=\"$_REQUEST[img_S_height]\",
						crop_S=\"".(0+$_REQUEST[crop_S])."\",
						
						var_L_width=\"$_REQUEST[var_L_width]\",
						var_L_height=\"$_REQUEST[var_L_height]\",
						var_L_crop=\"".(0+$_REQUEST[var_L_crop])."\",
						var_M_width=\"$_REQUEST[var_M_width]\",
						var_M_height=\"$_REQUEST[var_M_height]\",
						var_M_crop=\"".(0+$_REQUEST[var_M_crop])."\",
						var_S_width=\"$_REQUEST[var_S_width]\",
						var_S_height=\"$_REQUEST[var_S_height]\",
						var_S_crop=\"".(0+$_REQUEST[var_S_crop])."\",
						
						cat_L_width=\"$_REQUEST[cat_L_width]\",
						cat_L_height=\"$_REQUEST[cat_L_height]\",
						cat_L_crop=\"".(0+$_REQUEST[cat_L_crop])."\",
						cat_M_width=\"$_REQUEST[cat_M_width]\",
						cat_M_height=\"$_REQUEST[cat_M_height]\",
						cat_M_crop=\"".(0+$_REQUEST[cat_M_crop])."\",
						cat_S_width=\"$_REQUEST[cat_S_width]\",
						cat_S_height=\"$_REQUEST[cat_S_height]\",
						cat_S_crop=\"".(0+$_REQUEST[cat_S_crop])."\",
						
						analytics=\"$_REQUEST[analytics]\",
						n_decimali=\"$_REQUEST[n_decimali]\"
						";	
			$result = $this->db->query($query);
			if(!$result)exit("Errore salvataggio configurazione. ".mysql_error());
			$this->buildSession();
		}
	}
}
?>